<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.js"></script>
</head>
<body>

<button type="button" id="test_g">G</button> 37
<button type="button" id="test_c">C</button> 0
<button type="button" id="test_d">D</button> 3
<button type="button" id="test_t">T</button> 1
<button type="button" id="test_k">K</button> 0
<button type="button" id="test_1">1</button> 1
<script>
    $("#test_g").click(function () {
        count_train('G');
    })
    $("#test_c").click(function () {
        count_train('C');
    })
    $("#test_d").click(function () {
        count_train('D');
    })
    $("#test_t").click(function () {
        count_train('T');
    })
    $("#test_k").click(function () {
        count_train('K');
    })
    $("#test_1").click(function () {
        count_train('1');
    })


    //计算数量
    function count_train(type) {
        $.getJSON('train.json',function (data) {
            //采用filter过滤
            data.result.list =  data.result.list.filter(function(item){
                return item.train_type == type;
            });
            alert(data.result.list.length);
        })
    }
</script>
</body>
</html>